package com.app.freshmenapp.service.impl;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.app.freshmenapp.dao.NewsDao;
import com.app.freshmenapp.entity.News;

import com.app.freshmenapp.service.NewsService;;
@Service("newsService")
public class NewsServiceImpl implements NewsService {
	@Autowired
	NewsDao newsDao;
	@Override
	public boolean addNews(News news) {
		newsDao.save(news);
		if(news.getId()>0) {
			return true;
		}else {
			return false;
		}
	}

	@Override
	public boolean deleteNews(Integer id) {
		if(newsDao.existsById(id)) {
			newsDao.deleteById(id);
			return true;
		}else {
			return false;
		}
	}

	@Override
	public boolean updateNews(News news) {
		newsDao.save(news);
		if(news.getId()>0) {
			return true;
		}else {
			return false;
		}
		
	}

	@Override
	public News findNews(Integer id) {
		Optional<News> opt=  newsDao.findById(id);
		return opt.get();
	}

	@Override
	public List<News> findAllNews() {
		return newsDao.findAll();
	}

}
